﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gin.Commands;

namespace Gin.Commands
{
    [GinIgnoreType()]
    public abstract class CompareNumbersCommand: Command
    {
        public string FirstOperandName { get; set; }
        public string SecondOperandName { get; set; }
        public string ResultName { get; set; }

        public override void Do(ExecutionContext context)
        {
            bool result = Compare(Subtract(context));
            context.SaveResult(ResultName, result);
        }

        protected abstract bool Compare(int compareResult);

        private int Subtract(ExecutionContext context)
        {
            NumericOperand firstOperand = NumericOperand.Create(context.GetResult(FirstOperandName));
            NumericOperand secondOperand = NumericOperand.Create(context.GetResult(SecondOperandName));
            return (firstOperand - secondOperand);
        }
    }

    public class NumberLessThan : CompareNumbersCommand
    {
        protected override bool Compare(int compareResult)
        {
            return compareResult < 0;
        }
    }

    public class NumberGreaterThan : CompareNumbersCommand
    {
        protected override bool Compare(int compareResult)
        {
            return compareResult > 0;
        }
    }

    public class NumberEquals : CompareNumbersCommand
    {
        protected override bool Compare(int compareResult)
        {
            return compareResult == 0;
        }
    }

    public class NumberLessThanOrEquals : CompareNumbersCommand
    {
        protected override bool Compare(int compareResult)
        {
            return compareResult <= 0;
        }
    }

    public class NumberGreaterThanOrEquals : CompareNumbersCommand
    {
        protected override bool Compare(int compareResult)
        {
            return compareResult >= 0;
        }
    }

    public class NumberNotEquals : CompareNumbersCommand
    {
        protected override bool Compare(int compareResult)
        {
            return compareResult != 0;
        }
    }

}
